import request from '../../utils/request'


/**
 * 获取产品信息列表
 * @param page
 * @returns {Promise.<void>}
 */
export async function getProductApprovalList({productName, status, page}) {
    return request(apiPath.mc + "/api/products/approval", {
        method: 'get',
        data: {status, productName, page: page.page, size: page.size}
    });
}



/**
 * 获取产品信息列表
 * @param cstId
 * @param page
 * @returns {Promise.<void>}
 */
export async function getProductList({cstId, productName, productModel, status, page}) {
    return request(apiPath.mc + "/api/products", {
        method: 'get',
        data: {cstId, status, productName, productModel, page: page.page, size: page.size}
    });
}


/**
 * 增加产品信息
 * @param name
 * @param nameEn
 * @param branch
 * @param model
 * @param currency
 * @param price
 * @param unit
 * @param weight
 * @param size
 * @param declarelements
 * @param cstid
 * @param exporttype
 * @param sourcetype
 * @param memo
 * @param hscodehis
 * @param productFacade
 * @param productBranchModel
 * @param productCartons
 * @param productOtherFile
 * @param branchtype
 * @returns {Promise.<void>}
 */
export async function addProduct({
                                     name, nameEn, branch, model, currency, price, unit, weight, size, declarelements, cstid, exporttype, sourcetype, memo,
                                     hscodehis, productFacade, productBranchModel, productCartons, productOtherFile,branchtype, status
                                 }) {
    return request(apiPath.mc + "/api/product", {
        method: 'post',
        data: {
            name, nameEn, branch, model, currency, price, unit, weight, size, declarelements, cstid, exporttype, sourcetype, memo,
            hscodehis, productFacade, productBranchModel, productCartons, productOtherFile,branchtype, status}
    });
}


/**
 * 更新产品信息
 * @param id
 * @param name
 * @param nameEn
 * @param branch
 * @param model
 * @param currency
 * @param price
 * @param unit
 * @param weight
 * @param size
 * @param declarelements
 * @param cstid
 * @param exporttype
 * @param sourcetype
 * @param memo
 * @param hscodehis
 * @param productFacade
 * @param productBranchModel
 * @param productCartons
 * @param productOtherFile
 * @param branchtype
 * @returns {Promise.<void>}
 */
export async function updateProduct({
                                        id, name, nameEn, branch, model, currency, price, unit, weight, size, declarelements, cstid, exporttype, sourcetype, memo,
                                        hscodehis, productFacade, productBranchModel, productCartons, productOtherFile,branchtype, status
                                    }) {
    return request(apiPath.mc + "/api/product", {
        method: 'put',
        data: {
            id, name, nameEn, branch, model, currency, price, unit, weight, size, declarelements, cstid, exporttype, sourcetype, memo,
            hscodehis, productFacade, productBranchModel, productCartons, productOtherFile,branchtype, status
        }
    });
}

/**
 * 根据id查询产品信息
 * @param id
 * @returns {Promise.<void>}
 */
export async function getProductById({id}) {
    return request(apiPath.mc + "/api/product/"+ id, {
        method: 'get'
    });
}



/**
 * 删除产品信息
 * @param id
 * @returns {Promise.<void>}
 */
export async function deleteProductById({id}) {
    return request(apiPath.mc + "/api/product/"+ id, {
        method: 'delete'
    });
}


/**
 * 增加并提交审核产品信息
 * @param name
 * @param nameEn
 * @param branch
 * @param model
 * @param currency
 * @param price
 * @param unit
 * @param weight
 * @param size
 * @param declarelements
 * @param cstid
 * @param exporttype
 * @param sourcetype
 * @param memo
 * @param hscodehis
 * @param productFacade
 * @param productBranchModel
 * @param productCartons
 * @param productOtherFile
 * @param branchtype
 * @returns {Promise.<void>}
 */
export async function addProductAndSubmit({
                                     name, nameEn, branch, model, currency, price, unit, weight, size, declarelements, cstid, exporttype, sourcetype, memo,
                                     hscodehis, productFacade, productBranchModel, productCartons, productOtherFile,branchtype
                                 }) {
    return request(apiPath.mc + "/api/product/submit", {
        method: 'post',
        data: {
            name, nameEn, branch, model, currency, price, unit, weight, size, declarelements, cstid, exporttype, sourcetype, memo,
            hscodehis, productFacade, productBranchModel, productCartons, productOtherFile,branchtype}
    });
}

/**
 * 修改并提交审核产品信息
 * @param id
 * @param name
 * @param nameEn
 * @param branch
 * @param model
 * @param currency
 * @param price
 * @param unit
 * @param weight
 * @param size
 * @param declarelements
 * @param cstid
 * @param exporttype
 * @param sourcetype
 * @param memo
 * @param hscodehis
 * @param productFacade
 * @param productBranchModel
 * @param productCartons
 * @param productOtherFile
 * @param branchtype
 * @returns {Promise.<void>}
 */
export async function updateProductAndSubmit({
                                        id, name, nameEn, branch, model, currency, price, unit, weight, size, declarelements, cstid, exporttype, sourcetype, memo,
                                        hscodehis, productFacade, productBranchModel, productCartons, productOtherFile,branchtype
                                    }) {
    return request(apiPath.mc + "/api/product/submit", {
        method: 'put',
        data: {
            id, name, nameEn, branch, model, currency, price, unit, weight, size, declarelements, cstid, exporttype, sourcetype, memo,
            hscodehis, productFacade, productBranchModel, productCartons, productOtherFile,branchtype
        }
    });
}


/**
 * 产品审核
 * @param id
 * @param hscode
 * @param priceisok
 * @param iseffecthscode
 * @param drawbackcode
 * @param approvalresult
 * @param approvalmemo
 * @param businesstype
 * @param entityid
 * @returns {Promise.<void>}
 */
export async function productApproval({id, hscode, priceisok, iseffecthscode, drawbackcode, approvalresult, approvalmemo}) {
    let businesstype = "product";
    let entityid = id;
    return request(apiPath.mc + "/api/product/" + id + "/approval", {
        method: 'post',
        data: {
            id, hscode, priceisok, iseffecthscode, drawbackcode, approvalresult, approvalmemo, businesstype, entityid
        }
    });
}


